// 引入axios
import axios from '@/utils/request'

// 文章详情
export const detailsAPI = ({ artId }) =>
  axios({
    url: `/v1_0/articles/${artId}`
  })

// 用户-关注
export const userFollowedAPI = ({ userId }) =>
  axios({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: userId
    }
  })

// 用户-取消关注
export const userUnFollowedAPI = ({ userId }) =>
  axios({
    url: `/v1_0/user/followings/${userId}`,
    method: 'DELETE'
  })

// 文章 - 点赞
export const articleLikeAPI = ({ articleId }) =>
  axios({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: articleId
    }
  })

// 文章 - 取消点赞
export const articleDisLikeAPI = ({ articleId }) =>
  axios({
    url: `/v1_0/article/likings/${articleId}`,
    method: 'DELETE'
  })

// 评论 - 获取列表
export const commentListAPI = ({ artId, offset = null, limit = 10 }) =>
  axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset,
      limit
    }
  })

// 评论 - 喜欢
export const commentLikingAPI = ({ comId }) =>
  axios({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })

// 评论-取消喜欢
export const commentDisLikingAPI = ({ comId }) =>
  axios({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })

// 评论-发布评论
export const commentSendAPI = ({ id, content, art_id = null }) => {
  const obj = {
    target: id,
    content
  }
  if (art_id !== null) {
    obj.art_id = art_id
  }
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj
  })
}
